 layui.use(['form', 'element', 'jquery'], function() {
        var form = layui.form,
            element = layui.element,
            $ = layui.jquery;
        $('form').submit(function(event) {
            event.preventDefault();
            var ii = layer.load(2, {
                shade: [0.1, '#fff']
            });
            $.ajax({
                type: 'POST',
                url: '/h/ajax/Set',
                data: $(this).serialize(),
                dataType: 'json',
                success: function(data) {
                    layer.close(ii);
                    if (data.code == 1) {
                        layer.alert('设置保存成功！', {
                            icon: 1,
                            closeBtn: false
                        }, function() {
                            window.location.reload()
                        });
                    } else {
                        layer.alert(data.msg, {
                            icon: 2
                        })
                    }
                },
                error: function(data) {
                    layer.close(ii);

                    layer.msg('服务器错误');
                    return false;
                }
            });
            return false;
        });

        // 发送测试数据
        $("#testSendMail").click(function() {
            var ii = layer.load(2, {
                shade: [0.1, '#fff']
            });
            $.ajax({
                type: 'POST',
                url: '/h/ajax/emailcs',
                dataType: 'json',
                success: function(data) {
                    layer.close(ii);
                    if (data.code == 200) {
                        layer.alert('邮件发送成功！', {
                            icon: 1,
                            closeBtn: false
                        }, function() {
                            window.location.reload()
                        });
                    } else {
                        layer.alert(data.msg, {
                            icon: 2
                        })
                    }
                },
                error: function(data) {
                    layer.close(ii);

                    layer.msg('服务器错误');
                    return false;
                }
            });
            return false;
        });
        
        $("#testSendSMS").click(function() {
            var ii = layer.load(2, {
                shade: [0.1, '#fff']
            });
            $.ajax({
                type: 'POST',
                url: '/h/ajax/phonecs',
                
                dataType: 'json',
                timeout: 15000,
                success: function(data) {
                    layer.close(ii);
                    if (data.code ==200) {
                        layer.alert(data.msg, {
                            icon: 1,
                            closeBtn: false
                        }, function() {
                            window.location.reload()
                        });
                    } else {
                        layer.alert(data.msg, {
                            icon: 2
                        })
                    }
                },
                error: function(data) {
                    layer.close(ii);

                    layer.msg('服务器错误');
                    return false;
                }
            });
            return false;
        });
        

        function checkURL(obj) {
            var url = $(obj).val();

            if (url.indexOf(" ") >= 0) {
                url = url.replace(/ /g, "");
            }
            if (url.toLowerCase().indexOf("http://") < 0 && url.toLowerCase().indexOf("https://") < 0) {
                url = "http://" + url;
            }
            if (url.slice(url.length - 1) != "/") {
                url = url + "/";
            }
            $(obj).val(url);
        }
    });